using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace Zsa.Emulation.Util
{
    public static class SerializationHelper
    {
        public static object Clone(object obj)
        {
            if (!obj.GetType().IsSerializable)
            {
                throw new Exception();
            }
            using (MemoryStream _Stream = new MemoryStream())
            {
                BinaryFormatter _Formatter = new BinaryFormatter();
                _Formatter.Serialize(_Stream, obj);
                _Stream.Seek(0, SeekOrigin.Begin);
                obj = _Formatter.Deserialize(_Stream);
            }
            return obj;
        }
    }
}
